using System;
using System.Windows.Input;

namespace TimeToGo.Infrastructure
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class SimpleDelegateCommand<T> : ICommand
    {
        private readonly Action<T> _action;
        public event EventHandler CanExecuteChanged;

        private bool _executionStatus = true;
        public bool ExecutionStatus
        {
            get { return _executionStatus; }
            set
            {
                OnCanExecuteChanged();
                _executionStatus = value;
            }
        }

        protected virtual void OnCanExecuteChanged()
        {
            EventHandler handler = CanExecuteChanged;
            if (handler != null)
                handler(this, EventArgs.Empty);
        }

        public SimpleDelegateCommand(Action<T> action)
        {
            _action = action;
        }

        public void Execute(object parameter)
        {
            _action((T)parameter);
        }

        public bool CanExecute(object parameter)
        {
            return ExecutionStatus;
        }
    }
}